package com.cbgolf.oa.util;

import android.app.Activity;
import android.content.Intent;
import com.cbgolf.oa.R;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author lq
 * @date 2017/11/7
 */

public class ClassUtil {

    public static boolean isEquals(Class c1, Class c2) {
        return null != c1 && null != c2 && c1.equals(c2);
    }

    public static void startActivity(Activity act, Class clazz) {
        Intent intent = new Intent(act, clazz);
        act.startActivity(intent);
        act.overridePendingTransition(R.anim.in_from_right, R.anim.out_from_left);
    }

    public static void startActivity(Activity act, Class clazz, String key, boolean value) {
        Intent intent = new Intent(act, clazz);
        intent.putExtra(key, value);
        act.startActivity(intent);
        act.overridePendingTransition(R.anim.in_from_right, R.anim.out_from_left);
    }

    public static void startActivity(Activity act, Class c, String key, String value) {
        Map<String, String> map = new HashMap<>();
        map.put(key, value);
        startActivity(act, c, map);
    }

    public static void startActivity(Activity act, Intent intent) {
        if (null == act || null == intent) {
            return;
        }
        act.startActivity(intent);
        act.overridePendingTransition(R.anim.in_from_right, R.anim.out_from_left);
    }

    public static void startActivity(Activity act, Class clazz, Map<String, String> map) {
        Intent intent = new Intent(act, clazz);
        if (!CollectionUtil.mapIsNull(map)) {
            Set<Map.Entry<String, String>> set = map.entrySet();
            for (Map.Entry<String, String> me : set) {
                intent.putExtra(me.getKey(), me.getValue());
            }
        }
        act.startActivity(intent);
        act.overridePendingTransition(R.anim.in_from_right, R.anim.out_from_left);
    }

    public static void finish(Activity act) {
        if (null != act) {
            act.finish();
            act.overridePendingTransition(R.anim.in_from_left, R.anim.out_from_right);
        }
    }
}
